/*----------------------------------------------------------------------------*\
|
|						Public Interface to Muse Technology
|
|							     www.Muse.com
| Author : SunJun 
| Email : sundoom@msn.com
\*----------------------------------------------------------------------------*/

//////////////////////////////////////////////////////////////////////////
// $Id: Primitive.h,v 1.1 2008/12/20 12:20:36 sunjun Exp $
//////////////////////////////////////////////////////////////////////////

#ifndef __Primitive__
#define __Primitive__

//////////////////////////////////////////////////////////////////////////

#if defined __cplusplus

//////////////////////////////////////////////////////////////////////////

#include <Operation.h>

//////////////////////////////////////////////////////////////////////////

NAMESPACE_BEGIN

//////////////////////////////////////////////////////////////////////////

	// this class provides an object-oriented primitive interface.
	class API Primitive: public Operation
	{
	public:
		enum PrimitiveType
		{
			PT_POINTLIST		= 1,
			PT_LINELIST			= 2,
			PT_LINESTRIP		= 3,
			PT_TRIANGLELIST		= 4,
			PT_TRIANGLESTRIP	= 5,
			PT_TRIANGLEFAN		= 6,
			PT_FORCE_DWORD		= 0x7fffffff,
		};

	public:
		// constructor
		Primitive();
		
		// destructor
		virtual ~Primitive();

		// set the element type
		INLINE VOID	setPrimitiveType(U32 type);

		// get the element type
		INLINE U32 getPrimitiveType() const;

		// set the effect
		INLINE VOID	setEffect(const Effect * effect, const CHAR* technique = NULL);

		// get the shader
		INLINE const Effect* getEffect() const;

		// set the constant
		INLINE VOID setConstant( const CHAR* name, const Constant* constant );

		// get the constant
		INLINE const Constant* getConstant( const CHAR *name ) const;

		// set the vertex format
		INLINE VOID	setVertexFormat( const VertexFormat* vf );

		// get the vertex format
		INLINE const VertexFormat* getVertexFormat() const;

		// set the vertex buffer
		INLINE VOID	setVertexBuffer(const VertexBuffer* vb, U32 stream = 0, U32 offset = 0 );

		// get the vertex buffer
		INLINE const VertexBuffer* getVertexBuffer( U32 stream = 0 ) const;		

		// set the index buffer
		INLINE VOID	setIndexBuffer(const IndexBuffer * ib);

		// get the index buffer
		INLINE const IndexBuffer* getIndexBuffer() const;

		// locate the primitive
		INLINE VOID	locate( U32 vertex_offset, U32 vertex_count, U32 index_offset );

	private:
		// implement the render operation
		INLINE VOID operator() (class Context*rc);

	private:
		U32 mType;
		EffectPtr mEffectPtr;
		HANDLE mTechnique;
		std::map< Str, std::pair< ConstantPtr, HANDLE > >mConstants;
		VertexFormatPtr mVFPtr;
		std::vector< std::pair< VertexBufferPtr, U32 > >mVBs;
		IndexBufferPtr mIBPtr;
		U32 mVertexOffset, mVertexCount, mIndexOffset;
	};

	typedef MPtr<Primitive>PrimitivePtr;

//////////////////////////////////////////////////////////////////////////

NAMESPACE_END

//////////////////////////////////////////////////////////////////////////

#endif // __cplusplus

//////////////////////////////////////////////////////////////////////////

#endif // __Primitive__

//////////////////////////////////////////////////////////////////////////